package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.SearchIndex;
import com.cskaoyan.service.wx.WxSearchService;
import com.cskaoyan.util.UserInfoUtils;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author pengyehua
 * @date 2020/12/9 19:06
 */

/**
 * 搜索模块
 */
@RestController
@RequestMapping("wx/search")
public class WxSearchController {

    @Autowired
    WxSearchService wxSearchService;

    /**
     * 搜索关键词索引
     * @return
     */
    @RequestMapping("index")
    public BaseRespVo index(){
        Integer userId = UserInfoUtils.getUserId();
        SearchIndex searchIndex = wxSearchService.queryIndex(userId);
        System.out.println(userId);
        return BaseRespVo.ok(searchIndex);
    }

    /**
     * 删除搜索历史
     * @return
     */
    @RequestMapping("clearhistory")
    public BaseRespVo clearHistory(){
        Integer userId = UserInfoUtils.getUserId();
        wxSearchService.updateSearchHistory(userId);
        System.out.println(userId);
        return BaseRespVo.ok();
    }

    /**
     * 搜索关键字
     * @param keyword
     * @return
     */
    @RequestMapping("helper")
    public BaseRespVo helper(String keyword){
        List<String> list = wxSearchService.queryKeyword(keyword);
        return BaseRespVo.ok(list);
    }
}
